<?php

namespace addons\csmwj;

use think\Addons;
use app\common\library\Menu;
use addons\csmwj\library\xcore\xcore\utils\XcConfigUtils;

/**
 * 插件
 */
class Csmwj extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name' => 'csmwj',
                'title' => '工单调查小程序',
                'sublist' => [
                    [
                        'name' => 'csmwj/paper',
                        'title' => '工单管理',
                        'icon' => 'fa fa-meetup',
                        'sublist' => [
                            [
                                'name' => 'csmwj/paper/index',
                                'title' => '查看工单'
                            ],
                            [
                                'name' => 'csmwj/paper/add',
                                'title' => '添加工单'
                            ],
                            [
                                'name' => 'csmwj/paper/edit',
                                'title' => '修改工单'
                            ],
                            [
                                'name' => 'csmwj/paper/del',
                                'title' => '删除工单'
                            ],
                            [
                                'name' => 'csmwj/paper/port',
                                'title' => '访问端口'
                            ],
                            [
                                'name' => 'csmwj/paper/multi',
                                'title' => '批量处理'
                            ],
                            [
                                'name' => 'csmwj/paperiframe/formgenerate',
                                'title' => '工单维护'
                            ],
                            [
                                'name' => 'csmwj/csmwjadminapi/savepaperquestionjson?id=13',
                                'title' => '工单设置接口'
                            ],
                            [
                                'name' => 'csmwj/papercfg/edit',
                                'title' => '高级设置'
                            ],
                            [
                                'name' => 'csmwj/papertheme/edit',
                                'title' => '外观设置'
                            ],
                            [
                                'name' => 'csmwj/paper/getQDcodeImg',
                                'title' => '工单二维码'
                            ],
                            [
                                'name' => 'csmwj/paperstatistic/index',
                                'title' => '统计概况'
                            ],
                            [
                                'name' => 'csmwj/paperstatistic/answerlist',
                                'title' => '统计工单列表'
                            ],
                            [
                                'name' => 'csmwj/paperstatistic/paperdetail',
                                'title' => '统计工单详情'
                            ],
                            [
                                'name' => 'csmwj/paperstatistic/score',
                                'title' => '统计成绩'
                            ],
                            [
                                'name' => 'csmwj/paperstatistic/indexAjaxTrend',
                                'title' => '统计数据'
                            ],
                        ]
                    ],
                    [
                        'name' => 'csmwj/xp_paper_dashboard',
                        'title' => '统计数据',
                        'icon' => 'fa fa-meetup',
                        'sublist' => [
                            [
                                'name'  => 'csmwj/cloginthird/index',
                                'title' => '日志'
                            ],
                            [
                                'name' => 'csmwj/xp_paper_dashboard/index',
                                'title' => '统计0'
                            ],
                            [
                                'name' => 'csmwj/xp_paper_dashboard/getDatetimestringBeginclock',
                                'title' => '统计1'
                            ],
                            [
                                'name' => 'csmwj/xp_paper_dashboard/getDatetimestringEndclock',
                                'title' => '统计2'
                            ],
                            [
                                'name' => 'csmwj/xp_paper_dashboard/getDatetimeEndclock',
                                'title' => '统计3'
                            ],
                            [
                                'name' => 'csmwj/xp_paper_dashboard/getDatetimeBeginclock',
                                'title' => '统计4'
                            ],
                            [
                                'name' => 'csmwj/xp_paper_dashboard/getDatestringEndclock',
                                'title' => '统计5'
                            ],
                            [
                                'name' => 'csmwj/xp_paper_dashboard/getDatestringBeginclock',
                                'title' => '统计5'
                            ],
                            [
                                'name' => 'csmwj/xp_paper_dashboard/indexChartDataset',
                                'title' => '统计6'
                            ],
                        ],
                    ],
                ]
            ]
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete(XcConfigUtils::xpconfig('addons_code'));
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable(XcConfigUtils::xpconfig('addons_code'));
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable(XcConfigUtils::xpconfig('addons_code'));
        return true;
    }

    // Hook文档: https://doc.fastadmin.net/developer/87.html
    public function appInit()
    {
        $path = APP_PATH . '..' . \DIRECTORY_SEPARATOR . 'addons' . \DIRECTORY_SEPARATOR . 'csmwj' . \DIRECTORY_SEPARATOR . 'library' . \DIRECTORY_SEPARATOR . 'composer' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';

        require_once $path;
    }

    /**
     * JS 获取配置的方式 Config.csmsignin.cloginwxmp
     */
    public function configInit(&$params)
    {
        $config = $this->getConfig();
        $addons = XcConfigUtils::xpconfig('addons_code');
        $params[$addons] = [
            'cloginwxmp' => $config['cloginwxmp'],
            'cloginwxoa' => $config['cloginwxoa'],
        ];
    }

}
